import '../model/hourdata.dart';

import '../helper/dioHelper.dart';

class SumHour {
  int ID;
  double MaxH1;
  double MinH1;
  double MaxR;
  double MinR;
  double MaxQ;
  double MinQ;
  double WR;
  double WQz;
  double WQf;
  double WQp;
  double WQc;
  List<HourData> HList;

  SumHour(this.ID, this.MaxH1, this.MinH1, this.MaxR, this.MinR, this.MaxQ,
      this.MinQ, this.WR, this.WQz, this.WQf, this.WQp, this.WQc, this.HList);
  SumHour.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        MaxH1 = json["MaxH1"] * 1.0,
        MinH1 = json["MinH1"] * 1.0,
        MaxR = json["MaxR"] * 1.0,
        MinR = json["MinR"] * 1.0,
        MaxQ = json["MaxQ"] * 1.0,
        MinQ = json["MinQ"] * 1.0,
        WR = json["WR"] * 1.0,
        WQz = json["WQz"] * 1.0,
        WQf = json["WQf"] * 1.0,
        WQp = json["WQp"] * 1.0,
        WQc = json["WQc"] * 1.0,
        HList = HourData.GetListByValue(json["HList"]);
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'MaxH1': MaxH1,
        'MinH1': MinH1,
        'MaxR': MaxR,
        'MinR': MinR,
        'MaxQ': MaxQ,
        'MinQ': MinQ,
        'WR': WR,
        'WQz': WQz,
        'WQf': WQf,
        'WQp': WQp,
        'WQc': WQc,
        'HList': HList,
      };
  static Future<bool> Add(SumHour x1) async {
    var response = await DioHelper.Post("/SumHour/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(SumHour x1) async {
    var response = await DioHelper.Post("/SumHour/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(SumHour x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/SumHour/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<SumHour?> Get(String t1, String t2) async {
    //print(DioHelper.BaseUrl+"/DayData/GetSum?t1=$t1&t2=$t2");

    var response = await DioHelper.Get("/DayData/GetHourSum?t1=$t1&t2=$t2", {});
    print(response.data);
    if (response.statusCode == 200) return new SumHour.fromJson(response.data);
    return null;
  }

  static Future<List<SumHour>> GetList(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/SumHour/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 = <SumHour>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new SumHour.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<SumHour>> GetAllList() async {
    var response = await DioHelper.Get("/SumHour/GetAllList", {});
    var list1 = <SumHour>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new SumHour.fromJson(x));
      }
    }
    return list1;
  }
}
